﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RBAC.Web.Service;
using RBAC.Web.Models;
namespace RBAC.Web.Mapper
{
    public class UserMapper
    {
        public static UserModel DtoToModel(UserDto inputDto)
        {
            UserModel result = new UserModel();

            result.Id = inputDto.Id;
            result.Username = inputDto.Username;
            result.Password = inputDto.Password;
            result.Email = inputDto.Email;
            result.Mobile = inputDto.Mobile;

            result.CreateDate = inputDto.CreateDate;
            result.CreateById = inputDto.CreateById;
            result.UserStatus = inputDto.IsActive.GetValueOrDefault() ? 1 : 2;

            if (inputDto.Role != null)
            {
                result.Role = inputDto.Role.Id;

                result.RoleId = inputDto.Role.Id;
                result.RoleRoleCode = inputDto.Role.RoleCode;

            }
            //result.UserStatus = inputDto.UserStatus;

            return result;
        }


        public static UserDto ModelToDto(UserModel inputModel)
        {
            UserDto result = new UserDto();

            result.Id = inputModel.Id;
            result.Username = inputModel.Username;
            result.Password = inputModel.Password;
            result.Email = inputModel.Email;
            result.Mobile = inputModel.Mobile;

            result.CreateDate = inputModel.CreateDate;
            result.CreateById = inputModel.CreateById ;
            result.IsActive = inputModel.UserStatus == 1;

            if (inputModel.Role != 0)
            {
                result.Role = new RoleDto() { Id = inputModel.Role };
            }
            else
            {
                //result.Role = new RoleDto();
                result.Role = null;
            }

            //result.UserStatus = inputModel.UserStatus;

            return result;
        }

    }
}